'use strict';

const BaseController = require("../base");
const PosTagDto = require("../../dto/pos-tag.dto");
class PosTagController extends BaseController {

    /**
   * @description 分页查询列表
   * @param {PosTagDto.pageDto} 查询参数
   */
    async page() {
        try {
            const verifytRes = this.verifytParams(PosTagDto.pageDto);
            if (!verifytRes.success) throw verifytRes.msg;
            const res = await this.service.ucenter.posTag.page(verifytRes.params);
            if (!res.success) throw res.msg;
            await this.listSuccess(res.data.rows, res.data.count);
        } catch (err) {
            await this.error(err);
        }
    }

    /**
    * @description 获取指定类型下所有的标签
    */
    async select() {
        try {
            const verifytRes = this.verifytParams(PosTagDto.selectDto);
            if (!verifytRes.success) throw verifytRes.msg;
            const res = await this.service.ucenter.posTag.select(verifytRes.params);
            if (!res.success) throw res.msg;
            await this.success(res.data)
        } catch (err) {
            await this.error(err);
        }
    }

    /**
      * @description 创建文件夹
      * @param {PosTagDto.createDto} 参数
      */
    async create() {
        try {
            const verifytRes = this.verifytParams(PosTagDto.createDto);
            if (!verifytRes.success) throw verifytRes.msg;
            const res = await this.service.ucenter.posTag.create(verifytRes.params);
            if (!res.success) throw res.msg;
            await this.success();

        } catch (err) {
            await this.error(err);
        }
    }

    /**
     * @description 编辑
     * @param {PosTagDto.editDto} 参数
     */
    async edit() {
        try {
            const verifytRes = this.verifytParams(PosTagDto.editDto);
            if (!verifytRes.success) throw verifytRes.msg;
            const id = verifytRes.params.id;
            delete verifytRes.params.id;
            const res = await this.service.ucenter.posTag.edit(id, verifytRes.params);
            if (!res.success) throw res.msg;
            await this.success();
        } catch (err) {
            await this.error(err);
        }
    }

    /**
     * @description 删除
     * @param {PosTagDto.delDto} 参数
     */
    async del() {
        try {
            const verifytRes = this.verifytParams(PosTagDto.delDto);
            if (!verifytRes.success) throw verifytRes.msg;
            const res = await this.service.ucenter.posTag.del(verifytRes.params.id);
            if (!res.success) throw res.msg;
            await this.success();
        } catch (err) {
            await this.error(err);
        }
    }

}

module.exports = PosTagController;
